set more off

/* This file replicates the results in Table 2, Chegere, Eggert & Söderbom (CES) */ 

/*cd "C:\xxx....*/

discard 
clear all

use "CES2019_data.dta" /*, clear*/

keep if wave==1 & est_sample==1


/* this program uses wild bootstrap procedure for statistical tests based on regression without controls. */
prog def bt 
boottest {bagstreatment}{traintreatment}{bagstreatment=traintreatment}, cluster (villagecode) reps(999) seed (906453) nogr
boottest bagstreatment traintreatment, cluster (villagecode) reps(999) seed (906453) nogr
end

/* this program uses wild bootstrap procedure for statistical tests based on regression with controls */
prog def btf 
boottest {bagstreatment}{traintreatment}{bagstreatment=traintreatment}{sex}{age}{schooling}{activeworkers}{wealth}{maizeexperienceyears}{trained}, cluster (villagecode) reps(999) seed (906453) nogr
end


/* Table 2: Impact on post-harvest losses (note: infererence is not based on the std errors reported here)  */
reg prestolossprop bagstreatment traintreatment , cluster(villagecode)
bt
reg prestolossprop bagstreatment traintreatment sex age schooling activeworkers wealth maizeexperienceyears trained, cluster(villagecode)
btf
reg stolossprop bagstreatment traintreatment , cluster(villagecode)
bt
reg stolossprop bagstreatment traintreatment sex age schooling activeworkers wealth maizeexperienceyears trained, cluster(villagecode)
btf

/* Obtain p-values by means of randomised inference ("randomization-t randomized p-value") for treatment effects */
randcmd ((bagstreatment traintreatment) reg prestolossprop bagstreatment traintreatment, cluster(villagecode)), treatvars(bagstreatment traintreatment)  groupvar(village)
randcmd ((bagstreatment traintreatment) reg prestolossprop bagstreatment traintreatment sex age schooling activeworkers wealth maizeexperienceyears trained, cluster(villagecode)), treatvars(bagstreatment traintreatment)  groupvar(village)
randcmd ((bagstreatment traintreatment) reg stolossprop bagstreatment traintreatment, cluster(villagecode)), treatvars(bagstreatment traintreatment)  groupvar(village)
randcmd ((bagstreatment traintreatment) reg stolossprop bagstreatment traintreatment sex age schooling activeworkers wealth maizeexperienceyears trained, cluster(villagecode)), treatvars(bagstreatment traintreatment) groupvar(village)

exit

